The global Location API provides access to the device’s geographic location, including one-time location retrieval, reverse geocoding, user-driven location selection via map, accuracy control, and permission checking for widgets.
This API allows you to:
Note: This is a global API and does not require import.
Location.isAuthorizedForWidgetUpdates(): Promise<boolean>Checks whether widgets have permission to receive location updates.
Location.setAccuracy(accuracy: LocationAccuracy): Promise<void>Sets the desired accuracy level for location retrieval. Higher accuracy may increase battery usage and wait time.
| Value | Description |
|---|---|
"best" |
Maximum available accuracy |
"tenMeters" |
Within 10 meters |
"hundredMeters" |
Within 100 meters |
"kilometer" |
Within 1 kilometer |
"threeKilometers" |
Within 3 kilometers |
Location.requestCurrent(options?: { forceRequest?: boolean }): Promise<LocationInfo | null>Requests the user's current location once. May trigger a permission prompt if not previously granted.
By default, if a cached location is available, it will be returned immediately. If no cached location exists, a new request will be made. To force a new location retrieval even if a cached value exists, pass { forceRequest: true }.
| Option | Type | Required | Description |
|---|---|---|---|
forceRequest |
boolean |
No | If true, bypasses the cache and always requests new location. |
Location.pickFromMap(): Promise<LocationInfo | null>Opens the built-in map interface to allow the user to manually select a location.
Location.reverseGeocode(options): Promise<LocationPlacemark[] | null>Converts latitude and longitude into human-readable place information such as street, city, and country.
| Field | Type | Required | Description |
|---|---|---|---|
latitude |
number |
Yes | Latitude in degrees |
longitude |
number |
Yes | Longitude in degrees |
locale |
string |
No | Optional locale (e.g., "en-US"). Defaults to device language. |
LocationAccuracySpecifies the desired accuracy of location data:
LocationInfoRepresents a geographic coordinate with timestamp:
LocationPlacemarkRepresents a human-readable description of a geographic coordinate, typically returned by reverse geocoding. Includes structured location details such as city, country, and street.
| Field | Type | Description |
|---|---|---|
location |
LocationInfo |
The coordinates of the placemark (typically the same as reverse geocode input). |
region |
string |
General region or province/state. |
timeZone |
string |
Time zone identifier (e.g., "Asia/Shanghai"). |
name |
string |
Generic name such as building, landmark, or area. |
thoroughfare |
string |
Street name (e.g., "Main St", "Zhongguancun Ave"). |
subThoroughfare |
string |
Street-level detail like building number or unit. |
locality |
string |
City or town. |
subLocality |
string |
Subdivision of the locality (e.g., neighborhood or district). |
administrativeArea |
string |
Province, state, or equivalent administrative area. |
subAdministrativeArea |
string |
Further subdivision like county or district. |
postalCode |
string |
ZIP or postal code. |
isoCountryCode |
string |
ISO 3166-1 alpha-2 country code (e.g., "US", "CN"). |
country |
string |
Full name of the country or region. |
inlandWater |
string |
Name of nearby inland water (river/lake), if applicable. |
ocean |
string |
Name of nearby ocean, if applicable. |
areasOfInterest |
string[] |
List of nearby points of interest or landmarks (e.g., "Times Square"). |
areasOfInterest and name to display user-friendly place names.postalCode, locality, and administrativeArea for autofill and geotagging.timestamp to determine freshness of location data.timeZone for localizing time-based features.requestCurrent for optimal precision.isAuthorizedForWidgetUpdates().null is returned.forceRequest is false or omitted, cached location may be used for faster results.